<?php
############## DIT STUK CODE ZORGT ERVOOR DAT JE ALS ADMIN INGELOGD MOET ZIJN OM DE PAGINA TE KUNNEN ZIEN ##############
    //Start de sessie
    session_start();

    //Load de benodigde bestanden
    require_once("includes/auth.php");
########################################################################################################################
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Aanbieding instellen</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <link type="text/css" href="../css/pagination.css" rel="stylesheet" />
  <link rel="stylesheet" href="../css/reset.css" type="text/css" />
  <link rel="stylesheet" href="../css/960.css" type="text/css" />
  <link rel="stylesheet" href="../css/text.css" type="text/css" />
  <link type="text/css" href="../css/tablesorter.css" rel="stylesheet" />
  <link type="text/css" href="../css/sunny/jquery-ui-1.8.custom.css" rel="stylesheet" />
  <link type="text/css" href="../css/jquery.autocomplete.css" rel="stylesheet" />
  <link type="text/css" href="../css/style.css" rel="stylesheet" />
  <link type="text/css" href="../css/accmenu.css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery-1.4.2.min.js">
</script>
<script type="text/javascript" src="../js/jquery-ui-1.8.custom.min.js">
</script>
<script type="text/javascript" src="../js/jquery.tablesorter.js">
</script>
<script type="text/javascript" src="../js/jquery.autocomplete.min.js">
</script>
<script type="text/javascript" src="../js/menu.js">
</script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function()
    {
        $("#producttable").tablesorter();
    }
);
//]]>
</script>

</head>

<body>
  <div class="container_12">
    <div id="header" class="grid_12">

    </div>

    <div class="clear"></div>

    <div class="grid_12 spacer"></div>

    <div class="clear"></div>

    <div id="menu" class="grid_2">

        <?php
        include_once 'temp/menu_filler.php';
        ?>


    </div>

    <div id="adminarea" class="grid_10">
        <div id="tableholder">

              <?php

              // Connects to your Database
              include 'includes/connect.php';
              require_once("includes/twitter.php");

              setlocale(LC_ALL, 'nl_NL');

              {
              	      
              $begindate = mktime(0,0,0,$_POST['b_maand'],$_POST['b_dag'],$_POST['b_jaar']);
              $enddate = mktime(0,0,0,$_POST['e_maand'],$_POST['e_dag'],$_POST['e_jaar']);
              $today = mktime(0,0,0,date("m"),date("d"),date("Y")); 
              $verschil = ($enddate - $begindate);

           	   if( $begindate > $enddate)
           	   {
              	      die('Error: Einddatum kan niet eerder als begindatum zijn');
              	   }

              	   $sql="UPDATE product SET Promotieprijs='$_POST[promotieprijs]', begindate='$begindate', enddate='$enddate' WHERE productid='$_POST[productid]'";
              		   if (!mysql_query($sql))
              		   {
              		   	   die('Error: ' . mysql_error());
              	   	   }

                   $sql2 = "SELECT productnaam FROM product WHERE productid=" . $_POST[productid];
                   $result = mysql_query($sql2) or die("the query returned an error: " . mysql_error());
                   $row = mysql_fetch_array($result);

                   $naam = $row['productnaam'];

                   $message = $naam . " is in de aanbieding van " . strftime("%d %B %Y", $begindate) . " tot " . strftime("%d %B %Y", $enddate) . "!";

                   $twi_user = new Twitter("FoodWebz","project3");

                   $twi_user->updateStatus($message);

              	   echo "Promotieprijs ingesteld!";
              	   echo "<br />";
              	   echo "<br />";
              	   echo "<a href=\" manage_prod.php \"> Terug naar Productbeheer";
              	   




              }
              ?>

</div>
    </div>


    <div class="clear"></div>

    <div class="grid_12 spacer"></div>

    <div class="clear"></div>
</div>
</body>
</html>